package Java网络编程.TCP通信程序练习.p2_客户端数据来自键盘录入;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/*接收到的数据输出在控制台*/
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(2);

        //监听客户端连接
        Socket s = ss.accept();

       /* InputStream is  = s.getInputStream();
        byte[] bys = new byte[1024];
        int len;
        while((len=is.read(bys))!=-1){
            System.out.println(new String(bys,0,len));
        }*/

        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }

        ss.close();
    }
}
